Skip to content

fix(extgen): preserve parse error when file.Close() succeeds in class parser#2351

Open
alexandre-daubois wants to merge 1 commit intophp:mainfrom
alexandre-daubois:fix-classparser-close-error
Open

fix(extgen): preserve parse error when file.Close() succeeds in class parser#2351
alexandre-daubois wants to merge 1 commit intophp:mainfrom
alexandre-daubois:fix-classparser-close-error

Conversation

@alexandre-daubois
Copy link
Copy Markdown
Member

No description provided.

@dunglas dunglas requested a review from Copilot April 23, 2026 07:44
Comment on lines 214 to 217
e := file.Close()
if err != nil {
if err == nil {
err = e
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return errors.Join(err, file.Close())

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes error propagation in the extgen class parser so that parsing errors are not accidentally overwritten by a successful file.Close(), and adds a regression test to ensure an orphan //export_php:method directive correctly fails parsing.

Changes:

  • Fix parseMethods deferred Close() handling to only return a close error when parsing succeeded.
  • Add a unit test covering an orphan //export_php:method directive (not followed by a func).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/extgen/classparser.go Corrects deferred file-close error handling so parse errors are preserved.
internal/extgen/classparser_test.go Adds regression coverage for orphan method directive parsing failure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants